package blackhouse_servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import blackhouse_entity.subject;
import blackhouse_entity.subject_ID_boolean;
import blackhouse_server.Subjectadd_server;

import com.alibaba.fastjson.JSON;

@WebServlet("/subjectadd")
// 接收js地址
/**
 * 接收请求
 * **/
public class Subject_Add extends HttpServlet
{
	Subjectadd_server	aa	= new Subjectadd_server();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		// TODO Auto-generated method stub
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		String subjectCode = req.getParameter("subjectCode");
		String subjectName = req.getParameter("subjectName");
		String teacherName = (String) req.getSession().getAttribute("user");
		int gradeId = Integer.valueOf(req.getParameter("gradeID")).intValue();
		PrintWriter print = resp.getWriter();
		List<subject> list = null;
		String json = null;
		try
		{
			boolean isok = aa.subjectadd_server(subjectCode, subjectName,
					teacherName, gradeId);
			List<subject_ID_boolean> list1 = new ArrayList<subject_ID_boolean>();
			subject_ID_boolean sib = new subject_ID_boolean();
			sib.setID(teacherName);
			sib.setIsok(isok);
			list1.add(sib);
			String json1 = JSON.toJSONString(list1);
			print.write(json1);
		} catch (SQLException e)
		{
			e.printStackTrace();
		}
	}

}
